<template>
  <el-switch v-model="row.status" :disabled="isDisabled" :active-value="1" :inactive-value="0" @change="changeStatus" />
</template>

<script>
export default {
  props: {
    row: {
      type: Object,
      default: _ => {
        return {};
      }
    }
  },
  data() {
    return {
      disabled: false
    };
  },
  computed: {
    isDisabled() {
      // 是否禁止编辑状态
      if (this.disabled) {
        return true;
      }
      // 无权限时不可点击
      return !this.hasPermission({
        permission: 'course.live.large.edit'
      });
    }
  },
  methods: {
    changeStatus: function(value) {
      this.disabled = true;
      this.$http.put(
        '/course/admin/live/' + this.row.id + '/edit/status',
        { status: value },
        response => {
          // this.$message.success(response.msg, _ => {
          this.disabled = false;
          // });
        },
        error => {
          this.$message.error(error.msg);
        },
        false
      );
    }
  }
};
</script>

<style></style>
